<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <el-row class="searchBox searchInputWidth" :gutter="10">
        <el-form :inline="true" :model="filterField" ref="accountForm">
          <el-col :lg="8" :xl="6">
            <el-form-item label="申请日期" class="row-padding-bottom">
              <timeSelection
                @getStartTimeValue="getStartTimeValue"
                @getEndTimeValue="getEndTimeValue"
              ></timeSelection>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="企业归属" class="row-padding-bottom">
              <el-select
                v-model="filterField.belongs"
                placeholder="请选择"
                clearable
              >
                <el-option label="本地企业" value="1"></el-option>
                <el-option label="外地企业" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="经营地区" class="row-padding-bottom">
                <el-cascader
                  ref="manageArea"
                  v-model="bizAreaId"
                  :options="areasOptions"
                  @change="getAreaId"
                  clearable
                  filterable
                  :props="{ checkStrictly: true }"
                  placeholder="请选择"
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="行业" prop="industry">
                <el-cascader
                  ref="industry"
                  v-model="industryId"
                  :options="industryOptionsNC"
                  @change="getIndustryId"
                  :props="{ checkStrictly: true }"
                  clearable
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="审核状态" class="row-padding-bottom">
                <el-select
                  v-model="filterField.status"
                  placeholder="请选择"
                  clearable
                >
                  <el-option label="待审核" value="PENDING"></el-option>
                  <el-option label="审核通过" value="APPROVED"></el-option>
                  <el-option label="审核不通过" value="REFUSED"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="申请企业" class="row-padding-bottom">
                <el-input
                  placeholder="输入企业名称或统一社会信用代码"
                  clearable
                  v-model="filterField.keyword"
                  @blur="filterField.keyword = changeValue($event)"
                ></el-input>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchTable"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <!-- 列表 -->
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableData"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column
            align="center"
            prop="createTime"
            label="申请日期"
            :formatter="formatTd"
            width="110px"
          ></el-table-column>
          <el-table-column label="企业名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.name"
                :columnName="'name'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="uscc"
            label="企业统一社会信用代码"
            :formatter="formatTd"
            width="200"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="belongs"
            label="企业归属"
            :formatter="formatTd"
            min-width="110"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="bizAreaName"
            label="经营地区"
            :formatter="formatTd"
            min-width="140"
          >
            <template slot-scope="scope">
              {{ scope.row.bizCityName }}-{{ scope.row.bizCountyName }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="industryName"
            label="行业"
            :formatter="formatTd"
            min-width="180"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="status"
            label="审核状态"
            :formatter="formatTd"
            min-width="110"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="updaterName"
            label="审核人"
            :formatter="formatTd"
            min-width="110"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="updateTime"
            label="审核时间"
            :formatter="formatTd"
            width="110px"
          ></el-table-column>
          <el-table-column align="left" label="操作" fixed="right" width="110">
            <!-- 审核状态（PENDING：待审核，APPROVED：审核通过，REFUSED：审核不通过） -->
            <template slot-scope="scope">
              <!-- <el-link type="primary" v-if="scope.row.status ==='待审核' && hasPage"  @click="skipCheckPage(scope.row.id)" >审核</el-link> -->
              <div v-if="scope.row.status === '待审核' && hasPage">
                <el-link type="primary" @click="skipCheckPage(scope.row.id)"
                  >审核</el-link
                >
              </div>
              <div v-else-if="scope.row.status === '待审核' && !hasPage">
                <span>--</span>
              </div>
              <div v-else>
                <el-link
                  type="primary"
                  v-show="isShowDetail"
                  @click="skipCheckDetai(scope.row.id)"
                  >查看详情</el-link
                >
              </div>
              <!-- v-else-if -->
              <span v-show="!isShowDetail">--</span>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
          @getpageNo="getpageNo"
          @getpageSize="getpageSize"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'
import { mapActions, mapState } from 'vuex'
export default {
  name: 'checkCompanyAccount',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '企业审核',
      requestUrl: 'api-c/companyaudit/expand/companyauditlist', //表格请求路径
      date: [], //申请日期
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        },
      },
      loading: true,
      isShow: false,
      // 高级搜索 展开/关闭
      advanced: false,
      tableData: [], //表格数据
      industryId: '', //行业
      bizAreaId: '', //地址
      filterField: {
        beginDate: '',
        endDate: '',
        belongs: '', //归属
        bizAreaId: '', //地址
        industryId: '', //
        status: '', //审核状态
        keyword: '', //申请企业名称/代码
      },
      pageSize: 20,
      numberOfSearches: 3,
      pageNo: 1,
      hasPage: false,
      isShowDetail: '',
      screenWidth: '',
      timer: '',
    }
  },
  computed: { ...mapState(['areasOptions', 'industryOptionsNC']) },
  created() {
    this.$store.state.activeMenu = '/home/checkManage/checkCompanyAccount'
    //获取行业
    this.getIndustryNC({})
    //获取区域
    this.getAreas({ areaId: this.$store.state.areaInfoArr.areaId })
    this.filterField.status = this.$route.query.pending
      ? this.$route.query.pending
      : ''
    this.filterField.keyword = this.$route.query.name
      ? this.$route.query.name
      : ''
    this.bizAreaId = this.$route.query.areaId ? this.$route.query.areaId : ''
    this.filterField.bizAreaId = this.bizAreaId
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })

    this.hasPage =
      this.$store.state.buttonLimitsArr.indexOf('mCompanyAudit:update') > -1
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('mCompanyAudit:detail') > -1
  },
  mounted() {
    const _this = this
    window.onresize = () => {
      return (() => {
        // 可以在这里保存到浏览器中，也可以保存到其他地方
        // window.height = document.documentElement.clientHeight;
        // _this.height = window.height;
        _this.screenWidth = `${document.documentElement.clientWidth}`
      })()
    }
  },
  activated() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData(this.pageNo, this.pageSize)
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    ...mapActions(['getAreas', 'getIndustryNC']),
    /**
     * @description: 获取开始日期
     * @param {*} urls
     * @param {*} datas
     */
    getStartTimeValue(val) {
      if (val) {
        this.filterField.beginDate = val
      } else {
        this.filterField.beginDate = ''
      }
    },
    /**
     * @description: 获取结束日期
     * @param {*} urls
     * @param {*} datas
     */
    getEndTimeValue(val) {
      if (val) {
        this.filterField.endDate = val
      } else {
        this.filterField.endDate = ''
      }
    },
    getTableList(data) {
      this.tableData = data
      this.loading = false
      if (this.tableData.length < 1) {
        this.isShow = true
      }
    },
    //列表查询
    searchTable() {
      // if(!this.date || this.date==""  || this.date== null){
      //   this.$message({
      //       message: "请选择起止日期",
      //       type: "warning"
      //   });
      //   return;
      // }根据产品要求去掉
      this.pageSize = 20
      this.pageNo = 1
      this.$refs.pagination.getTableListData()
    },
    //获取选中的区域最后一级id
    getAreaId() {
      var areaId = this.bizAreaId[this.bizAreaId.length - 1]
      this.filterField.bizAreaId = areaId
    },
    //获取选中的行业最后一级id
    getIndustryId() {
      var industryId = this.industryId[this.industryId.length - 1]
      this.filterField.industryId = industryId
    },
    //跳转审核页面
    skipCheckPage(id) {
      this.$router.push({
        name: 'checkPage',
        path: 'home/checkManage/checkPage',
        query: {
          id: id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/checkManage/checkCompanyAccount',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    //跳转详情页面
    skipCheckDetai(id) {
      this.$router.push({
        name: 'checkDetailPage',
        path: 'home/checkManage/checkDetailPage',
        query: {
          id: id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/checkManage/checkCompanyAccount',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style scoped lang="less">
@media only screen and (max-width: 1366px) {
  /deep/.searchInputWidth .el-form--inline .el-form-item__label {
    width: 80px;
  }
}

.searchBox {
  padding: 0px 24px;
}

/deep/ form.el-form.el-form--inline {
  padding: 0px 20px;
}

@import '../../../static/css/filterArea.less';
</style>
